home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1996 September
/
MACPOWER-1996-09.ISO.7z
/
MACPOWER-1996-09.ISO
/
第2特集:プラグイン大集合
/
PIC2 Save
/
pic2.h
< prev
next >
Wrap
Text File
|
1995-01-16
|
9KB
|
332 lines
/*
*
* PIC2 ヘッダーファイル by やなぎさわ
*
* for X680x0/MS-DOS/GO32 Modifyed Noboru Abe
* for RUN386/EXE386 Modifyed メルキュール
* for 8bit color test Modifyed やなぎさわ
* int->long
*/
#pragma once
#if 0
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <io.h>
#endif
#ifndef _PIC2_INCLUDED
#define _PIC2_INCLUDED
#if defined( __HUMAN68K__) && !defined( __X68__)
# define __X68__
#endif
#ifdef __X68__
# define BIG_ENDIAN
#endif
#if defined(__THINK__) || defined(__MWERKS__)
# define PADDING_STRUCT /* 構造体に隙間ができる時に定義 */
#define BIG_ENDIAN
#define _HUGE_
#include <string.h>
#include <setjmp.h>
#define memcpy(d,s,n) BlockMove((s),(d),(n))
#endif
#ifdef __GO32__
# define PADDING_STRUCT /* 構造体に隙間ができる時に定義 */
#endif
#ifdef __RUN386__
# pragma On(Pointers_compatible)
# pragma Off(Char_default_unsigned)
# include <fcntl.h>
#endif
#ifdef __GO32__
# include <unistd.h>
#endif
#ifdef __MWERKS__
# define HALLOC(a,b) NewPtrClear((long)a*b)
# define HFREE(a) DisposePtr(a)
#endif
#ifdef _DOS_
# include <fcntl.h>
# ifdef _MSC_VER
# include <malloc.h>
# define _HUGE_ _huge
# define HALLOC(a,b) halloc(a,b)
# define HFREE(a) hfree(a)
# else
# ifdef __TURBOC__
# include <alloc.h>
# define _HUGE_ far
# define HALLOC(a,b) farcalloc(a,b)
# define HFREE(a) farfree(a)
# else
# define _HUGE_
# define HALLOC(a,b) malloc((long)a*b)
# define HFREE(a) free(a)
# endif /* __TURBOC__ */
# endif /* _MSC_VER */
#else
#if 0
# define _HUGE_
# ifdef _RUN386__
# include <fcntl.h>
# else
# include <sys/fcntl.h>
# endif /* _HUGE_ */
#endif
#endif /* _DOS_ */
#ifdef _PIC2_
# define EXT
#else
# define EXT extern
#endif
/* 簡単な型の定義 (環境によっては定義済みの可能性あり) */
#ifndef UCHAR
# define UCHAR
typedef unsigned char uchar;
typedef signed char schar; /* 符号付きchar */
typedef unsigned short ushort; /* これは結構定義済みかな? */
typedef unsigned long ulong;
#endif
typedef ulong pix; /* 画素ね */
/*
* pic2libのエラーコード
*(errnoと重ならないようにすること8bit以上なので終了コードに使うのは注意 :-)
*/
#define P2E_FEOF 257 /* EOFを超えてファイルを読み込もうとした */
#define P2E_BADFORM 258 /* フォーマットが未知または不正または異常 */
/* PIC2ファイルのオープンモード */
#define P2_OPEN_READ 0
#define P2_OPEN_WRITE 1
/* その他の定義 */
#define N_FBUF (8*1024) /* ファイルバッファのサイズ */
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
/* 変更してはいけない定義 (ここだけ変えても旨くいかない ^^;) */
#define COLOR_CACHE_BITS 5
#define N_COLOR_CACHE ((1<<COLOR_CACHE_BITS) - 1) /* 算術版の色キャッシュサイズ */
#define N_CONTEXT 128 /* 算術版の確率空間数 */
#define CACHE_BITS 6
#define N_CACHE (1<<CACHE_BITS) /* 高速版の色キャッシュサイズ */
#ifdef BIG_ENDIAN
# define SHORT short
# define LONG long
# define SHORT2short( n) (n)
# define LONG2long( n) (n)
# define short2SHORT( n) (n)
# define long2LONG( n) (n)
# define mem2short( addr) (*(short *)(addr))
# define mem2long( addr) (*(long *)(addr))
#else
typedef short SHORT;
typedef long LONG;
extern short SHORT2short( SHORT n);
extern long LONG2long( LONG n);
extern SHORT short2SHORT( short n);
extern LONG long2LONG( long n);
# define mem2short( addr) SHORT2short(*(SHORT *)(addr))
# define mem2long( addr) LONG2long(*(LONG *)(addr))
#endif
/* PIC2 のヘッダ イメージ (パディング無しで詰まっていなくてはいけない)*/
struct p2_hdr {
/* 0 */ uchar magic[4]; /* ヘッダID "P2DT" */
/* 4 */ uchar name[18]; /* 作者名 */
/* 22 */ uchar subtitle[8]; /* セーブ時のファイル名先頭8文字 */
/* 30 */ uchar crlf0[2]; /* CRLF */
/* 32 */ uchar title[30]; /* タイトル名 */
/* 62 */ uchar crlf1[2]; /* CRLF */
/* 64 */ uchar saver[30]; /* セーバー名 */
/* 94 */ uchar crlf2[2]; /* CRLF */
/* 95 */ uchar eof; /* 終端 */
/* 97 */ uchar reserve0; /* 空白エリア */
/* 98 */ SHORT flag; /* FLG */
/* 100 */ SHORT no; /* 作品番号 */
/* 102 */ LONG time; /* 日付 */
/* 106 */ LONG size; /* ヘッダサイズ */
/* 110 */ SHORT depth; /* 色数(ビット深さ) */
/* 112 */ SHORT x_aspect; /* 横方向ドット比率 */
/* 114 */ SHORT y_aspect; /* 縦方向ドット比率 */
/* 116 */ SHORT x_max; /* 画像最大サイズX */
/* 118 */ SHORT y_max; /* 画像最大サイズY */
/* 120 */ long reserve1; /* 空白エリア */
/* uchar pal[][3]; パレットとコメントはサイズ不定なので別 */
/* uchar comment; */
};
#define SIZE_OF_HEADER 124
/* ブロックのヘッダ イメージ */
struct p2_blk {
/* 0 */ uchar id[4]; /* 圧縮ID */
/* 4 */ LONG size; /* サイズ */
/* 8 */ SHORT flag; /* フラグ */
/* 10 */ SHORT x_wid; /* 画像サイズX */
/* 12 */ SHORT y_wid; /* 画像サイズY */
/* 14 */ SHORT x_offset; /* オフセットX */
/* 16 */ SHORT y_offset; /* オフセットY */
/* 18 */ LONG opaque; /* 透明色 */
/* 22 */ LONG reserve; /* 空きエリア */
};
#define SIZE_OF_BLK 26
/* PIC2 の各種ルーチンのハンドラ */
typedef struct _P2 {
struct p2_hdr header; /* ヘッダイメージ */
struct p2_blk blk; /* ブロックヘッダ */
short n_pal; /* パレット数 */
short pal_bits; /* パレット有効ビット数 */
uchar pal[256][3]; /* パレット格納場所 */
uchar *comment; /* コメント */
short fds; /* ファイルでぃすくりぷた */
uchar mode; /* 'r'=read/'w'=write モード */
long macbin_offset; /* macバイナリのオフセット量 */
short errno; /* エラーが入る
* < 0x100 : <errno.h>と同じ
* >= 0x100 : pic2独自のエラー
*/
long next_pos; /* 次のブロックの位置(load時) */
long blk_pos; /* 現loadブロックの位置 */
short x_max; /* 最大幅 */
short y_max; /* 最大高 */
long ynow; /* 展開/圧縮中のライン */
uchar *buff; /* ユーザが与えたバッファ
* ここがNULLだとこっちでmallocする
*/
long n_buff; /* バッファのサイズ */
/* 展開/圧縮に使う各種バッファ */
pix *vram_prev;
pix *vram_now;
pix *vram_next;
schar *flag_now;
schar *flag_next;
schar *flag2_now;
schar *flag2_next;
schar *flag2_next2;
pix (_HUGE_ * cache)[N_COLOR_CACHE + 1];
ushort *cache_pos;
ushort *mulu_tab;
/* 展開/圧縮に使うファイルバッファと算術部のパラメータ */
uchar fbuf[N_FBUF];
uchar *fbufp;
long n_fbuf;
ushort bit_buf;
short n_bit_buf;
long aa;
long cc;
long dd;
char cache_hit_c; /* 前回色キャッシュにヒットしてるか?
* 15 当たり/ 16 外れ
* (15/16は算術圧縮の空間番号ね)
*/
/* 展開/圧縮に使う関数へのポインタ */
long (*nextline)( struct _P2 *p2, pix **line);
/* 他に取っておきたい変数を入れるところ */
pix (* func)(pix );
long data;
} P2;
/* メモリの確保と開放関係 */
#define NEW( m) ((m) = mem_alloc( sizeof( *(m))))
#if __MWERKS__
#define FREE( m) { if ( m != NULL) { DisposePtr((Ptr) m); m = NULL; } }
#else
#define FREE( m) { if ( m != NULL) { free( m); m = NULL; } }
#endif
/* 各種ワークなど */
EXT short p2errno; /* エラーの原因が入る */
EXT char raw_beta; /* べた時のラインバッファを 0=他と同じ/1=ベタ */
/* プロトタイプ宣言 */
void l_memset( void *mem, uchar data, long n);
long read_file( P2 *p2, void *mem, long size);
long read_file2( P2 *p2, void *mem, long size);
uchar read_char( P2 *p2);
ushort read_short( P2 *p2);
long write_file( P2 *p2, void *mem, long size);
long write_char( P2 *p2, char a);
long write_short( P2 *p2, short n);
long write_long( P2 *p2, long n);
long seek_file( P2 *p2, long pos);
long tell_file( P2 *p2);
void p2setpal( short p_n_pal, short p_pal_bits, uchar p_pal[][3]);
void p2setenv( char *savername, short ncolor, long xmax, long ymax, short xasp
, short yasp, short rawbeta);
void p2setbuff( P2 *p2, long *buff, long n_buff);
#ifdef __MWERKS__
P2 *p2creat( FSSpec *fname, char *title, char *comment, char *name, short no);
P2 *p2apend( FSSpec *fname, char *title, char *comment, char *name, short no);
P2 *p2open( FSSpec *fname);
#else
P2 *p2creat( char *fname, char *title, char *comment, char *name, short no);
P2 *p2apend( char *fname, char *title, char *comment, char *name, short no);
P2 *p2open( char *fname);
#endif
short p2close( P2 *p2);
short p2next( P2 *p2);
short p2find( P2 *p2);
short p2load( P2 *p2);
long p2save( P2 *p2, pix **line, long x, long y, long xw, long yw, char *id, pix opaque);
long p2nline( P2 *p2, pix **line);
void p2error( char *s);
long p2sf_sv_init( P2 *p2, pix **line);
long p2b_sv_init( P2 *p2, pix **line);
long p2ss_sv_init( P2 *p2, pix **line);
long p2ss_ld_init( P2 *pp2);
long p2b_ld_init( P2 *p2);
long p2sf_ld_init( P2 *p2);
long line_press( P2 *pp2, pix **line);
short bit_decode(long c);
short nn_decode( long c);
pix read_color15( pix x);
pix read_color24( pix x);
#endif /* _PIC2_INCLUDED */